package com.example.demo.mvp.model;

import rx.Subscription;
import rx.subscriptions.CompositeSubscription;

public class BaseModel implements IModel {
    private CompositeSubscription compositeSubscription;
    @Override
    public void addSubscription(Subscription subscription) {
        if (compositeSubscription == null){
            compositeSubscription = new CompositeSubscription();
        }

        compositeSubscription.add(subscription);
    }

    @Override
    public void unSubscription() {
        if (compositeSubscription != null && !compositeSubscription.isUnsubscribed()){
            compositeSubscription.clear();
            compositeSubscription.unsubscribe();
        }
    }
}
